import os,sys
import calJuncCoverage
rootdir = "../outputs"
juncdir = "../supposedVSfound"

outputdir = "../supposedVSfound/calJuncCovOut"
index=[]
index = range(1,20)
index.append("X")
index.append("Y")

signals = {}

BASE = {"A":"T","C":"G","G":"C","T":"A"}

for i in index:
    currJuncFile = os.path.join(juncdir,'supposed.rawbin.splicemap.chr%s.new.bed'%(str(i),))
    print currJuncFile
    rawbinReadFile = os.path.join(rootdir,"rawbin/simulated/chr%s/Mapped_modified.bam"%(str(i),))
    spliceReadFile = os.path.join(rootdir,"splicemap/simulated/chr%s/good_hits.bam"%(str(i),))
    tophatReadFile = os.path.join(rootdir,"tophat/simulated/chr%s/accepted_hits.bam"%(str(i),))
    simulatedReadFile = os.path.join("../mm9-chromosome-single/bam/chr%s.bam"%(str(i),))

    rawbinoutfile = os.path.join(outputdir,"rawbin_chr%s.txt"%(str(i),))
    # Deal with Rawbin reads first.
    print "rawbin"
    os.system("python calJuncCoverage.py -j %s -r %s -a %d -c %d -o %s"%(currJuncFile, rawbinReadFile,10,15,rawbinoutfile))
    # Deal with Splicemap reads
    spliceoutfile = os.path.join(outputdir,"splice_chr%s.txt"%(str(i),))
    print "splicemap"
    os.system("python calJuncCoverage.py -j %s -r %s -a %d -c %d -o %s"%(currJuncFile, spliceReadFile,10,15,spliceoutfile))
    tophatoutfile = os.path.join(outputdir,"tophat_chr%s.txt"%(str(i),))
    print "tophat"
    os.system("python calJuncCoverage.py -j %s -r %s -a %d -c %d -o %s"%(currJuncFile, tophatReadFile,10,15,tophatoutfile))
    simulatedoutfile = os.path.join(outputdir,"simulated_chr%s.txt"%(str(i),))
    print "original reads"
    os.system("python calJuncCoverage.py -j %s -r %s -a %d -c %d -o %s"%(currJuncFile, simulatedReadFile,0,15,simulatedoutfile))
    tempjunctions,tempsignals = calJuncCoverage.getJunctions(currJuncFile,True)
    for sig in tempsignals:
        sigRev = ""
        for base in sig:
            sigRev = BASE[base] + sigRev
        if sig in signals:
            signals[sig] += tempsignals[sig]
        elif sigRev in signals:
            signals[sigRev] += tempsignals[sig]
        else:
            signals[sig] = tempsignals[sig]

print "\n----------------------Summary---------------------------"
for key in signals:
    print key,' ',signals[key]
